<template>
	<view style="padding: 20rpx;">
		<el-button type="primary" style="margin-bottom: 20rpx;" size="mini" @click="show1 = true">
			新增朋友圈文案
		</el-button>

		<block v-for="(data,index) in tableData" :key="index">
			<view style="margin: 20rpx 0;">{{data.classDesc}}</view>
			<el-table :data="data.results" style="width: 100%" stripe border size="mini">
				<el-table-column type="index" width="50">
				</el-table-column>
				<el-table-column prop="content" label="内容">
				</el-table-column>
				<el-table-column prop="classDesc" label="分类">
				</el-table-column>
				<el-table-column prop="createdAt" label="创建日期">
				</el-table-column>
				<el-table-column fixed="right" label="操作" width="100">
					<template slot-scope="scope">
						<el-button @click="deleteThis(scope.row)" type="text" size="small">删除</el-button>
						<el-button type="text" size="small" @click="editThis(scope.row)">编辑</el-button>
					</template>
				</el-table-column>
			</el-table>
		</block>

		<contentImageEdit v-if="show1" @save="show1 = false,chooseItem='',getData()" :detail="chooseItem"
			@close="show1 = false,chooseItem = ''" />
	</view>
</template>

<script>
	import contentImageEdit from '@/components/contentImageEdit'
	let that
	export default {
		components: {
			contentImageEdit
		},
		data() {
			return {
				show1: false,
				chooseItem: '',
				tableData: []
			}
		},

		onLoad() {
			that = this
			that.getData()
		},

		methods: {
			deleteThis(item) {
				console.log(item)
				uni.showModal({
					content: "是否删除此条目",
					success(res) {
						if (res.confirm) {
							that.$http.Post("admin/contentImage/destroy", {
								objectId: item.objectId
							}, "加载中...").then(res => {
								that.getData()
							})
						}
					}
				})
			},

			editThis(item) {
				this.chooseItem = item
				this.show1 = true
			},

			getData() {
				this.$http.Post("admin/contentImage/list", {}, "加载中...").then(res => {
					this.tableData = res.data
				})
			}
		}
	}
</script>

<style>

</style>
